import sys

import pygame

from python_basic_book.practise.alien_invasion.settings import Settings
from python_basic_book.practise.alien_invasion.ship import Ship


def run_game():
    # 初始游戏并创建一个屏幕对象
    pygame.init()

    settings = Settings()

    screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    # 创建一艘飞船
    ship = Ship(screen)

    # 开始游戏的主循环
    while True:
        # 监视键盘与鼠标事标
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        # 每次循环时都会重绘屏幕
        screen.fill(settings.bg_color)
        ship.blitme()

        # 让绘制的屏幕可见
        pygame.display.flip()

run_game()